package com.whw.cbf_qimodazuoye.entity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.whw.cbf_qimodazuoye.R;
import java.util.List;


public class CheckOrdersAdapter extends ArrayAdapter<CheckOrders> {


    private int resourceId;  //这个参数其实是每个item的layout
    private Context context2;
    public CheckOrdersAdapter(@NonNull Context context, int resource, @NonNull List<CheckOrders> objects) {
        super(context, resource, objects);
        resourceId = resource;
        context2= context;
    }

    public View getView(int position, View convertView, ViewGroup parent){
        final CheckOrders checkOrders = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId,null);
        ImageView hotelCoverpic = (ImageView)view.findViewById(R.id.hotelImage);
        TextView hotelName = (TextView)view.findViewById(R.id.hotelName);
        TextView checkOrdersCheckInTime = (TextView)view.findViewById(R.id.checkOrdersCheckInTime);

        TextView checkOrdersStatus = (TextView)view.findViewById(R.id.checkOrdersStatus);
        Hotel hotel = checkOrders.getHotel();
        if (hotel.getHotelName()!=null)
        hotelName.setText(hotel.getHotelName());

        if (checkOrders.getCheckOrdersCheckInTime()!=null)
        checkOrdersCheckInTime.setText(checkOrders.getCheckOrdersCheckInTime());

        if (checkOrders.getCheckOrdersStatus()!=null){
            switch (checkOrders.getCheckOrdersStatus()){
                case "-1":
                    checkOrdersStatus.setText("拒绝入住");
                    break;
                case "0":
                    checkOrdersStatus.setText("已预定");
                    break;
                case "1":
                    checkOrdersStatus.setText("已取消");
                    break;
                case "2":
                    checkOrdersStatus.setText("已完成");
                    break;
            }

        }


        String pic[] = hotel.getHotelCoverpic().split(";");

        Glide.with(this.getContext())
                .load(pic[0])
                //设置占位图
                .placeholder(R.mipmap.ic_launcher)
                //加载错误图
                .error(R.mipmap.ic_launcher)
                //磁盘缓存的处理
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(hotelCoverpic);


        return view;
    }


}
